﻿////////////////////////////////////////////////////////////////////////////////
// Source Copyright (C) J.Fan
// @author      J.Fan
// @date        2013-01-19
// @revision    Revision in Version Control System
// @remark      
////////////////////////////////////////////////////////////////////////////////

using System;
using System.Text;
using JsonConverter.Converter;
using JsonConverter.Writer;

namespace JsonConverter
{
    /// <summary>
    /// This class is main class to convert a object to a JSON string.
    /// </summary>
    public static class JsonConverter
    {
        public static string Convert(object value, ConverterProvider converterProvider = null)
        {
            StringBuilder builder = new StringBuilder();
            using (StringBuilderJsonWriter writer = new StringBuilderJsonWriter(builder, converterProvider))
            {
                writer.Write(value);
                return builder.ToString();
            }
        }

        public static void RegisterDefaultConverter(IPrimitiveConverter converter, params Type[] types)
        {
            ConverterProvider.Default.Register(converter, types);
        }

        public static void RegisterDefaultConverter(IObjectConverter converter, params Type[] types)
        {
            ConverterProvider.Default.Register(converter, types);
        }
    }
}
